/*
 * @Description: 
 * @Author: 赵大壮
 * @Date: 2021-12-11 13:29:12
 * @LastEditTime: 2022-05-23 18:17:16
 * @LastEditors: 赵大壮
 */
import { MessageBox } from 'element-ui';
class DZMessageBox {

    install() {
        // 初始化调用
    }

    normal(msg: string, btnMsg: string, todo: () => void) {
        MessageBox.confirm(msg, "提示", {
            confirmButtonText: btnMsg,
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            todo();
        }).catch(() => {
        });
    }

    del(msg: string, todo: () => void) {
        MessageBox.confirm(msg, "提示", {
            confirmButtonText: '删除',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            todo();
        }).catch(() => {
        });
    }

    warning(msg: string, todo: () => void) {
        MessageBox.confirm(msg, "提示", {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            todo();
        }).catch(() => {
        });
    }

    change(msg: string, todo: () => void, cancel: () => void) {
        MessageBox.confirm(msg, "提示", {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
        }).then(() => {
            todo();
        }).catch(() => {
            cancel();
        });
    }


    // box(msg: string,type_label:string,confirm_text:string,cancel_text:string, todo: () => void, cancel: () => void) {
    //     MessageBox.confirm(msg, "提示", {
    //         confirmButtonText: confirm_text ?? '确定',
    //         cancelButtonText: cancel_text ?? '取消',
    //         type: type_label ?? 'warning'
    //     }).then(() => {
    //         todo();
    //     }).catch(() => {
    //         cancel();
    //     });
    // }

    export(msg: string, all: () => void, page: () => void) {
        MessageBox.confirm(msg, "导出提示", {
            distinguishCancelAndClose: true,
            confirmButtonText: '导出全部',
            cancelButtonText: '导出本页',
        }).then(() => {
            all();
        }).catch((action) => {
            if (action == 'cancel') {
                page();
            }
        });
    }

    prompt(msg: string, input_value: string, todo: (value: any) => void) {
        MessageBox.prompt('', msg, {
            inputValue: input_value,
            confirmButtonText: '确定',
            cancelButtonText: '取消'
        }).then((value) => {
            todo(value);
        }).catch(() => {
        });
    }


    promptValidator(msg: string, input_value: string, input_pattern: any, input_error_message: string, todo: (value: any) => void) {
        MessageBox.prompt('', msg, {
            inputValue: input_value,
            inputPattern: input_pattern,
            inputErrorMessage: input_error_message,
            confirmButtonText: '确定',
            cancelButtonText: '取消'
        }).then((value) => {
            todo(value);
        }).catch(() => {
        });
    }
}
const dzMsgBox = new DZMessageBox();
export default dzMsgBox;
